﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Project2
{
    internal class 自定义强制类型转换
    {
        private static void Main自定义强制类型转换(string[] args)
        {
            Stone stone = new Stone();
            stone.age = 5000;
            Monkey wukong = (Monkey)stone;
            Console.WriteLine(wukong.age);

            Liuer liu = stone;
            Console.WriteLine(liu.age);
            double d = 2.0;
            List<int> list = new List<int>();
            char a = 'a';
            var inta = (ushort)a;
            Console.WriteLine(inta);
        }
    }

    internal class Monkey
    {
        public int age;
    }

    internal class Liuer
    {
        public int age;
    }

    internal class Stone
    {
        public int age;

        //类似Monkey的构造函数
        //显式转换
        public static explicit operator Monkey(Stone stone)
        {
            Monkey monkey = new Monkey();
            monkey.age = stone.age / 100;
            return monkey;
        }

        //隐式转换
        public static implicit operator Liuer(Stone stone)
        {
            Liuer monkey = new Liuer();
            monkey.age = stone.age / 10;
            return monkey;
        }
    }
}